package com.xv.service;

import com.xv.dao.EmpMapper;
import com.xv.pojo.Emp;
import com.xv.pojo.EmpExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("EmployeeServiceImp")
public class EmployeeServiceImp implements EmployeeService {
    @Autowired
    private EmpMapper empMapper;
    public List<Emp> getAll() {
        return empMapper.selectByExampleWithDept(null);
    }

    public int saveEmp(Emp emp) {

        return empMapper.insert(emp);
    }

    public boolean checkuser(String empName) {
        EmpExample example = new EmpExample();
        EmpExample.Criteria criteria = example.createCriteria();
        criteria.andEmpNameEqualTo(empName);
        long count  = empMapper.countByExample(example);
        return count == 0;
    }
    /*
    *根据员工ID查询员工信息
    */
    public Emp getEmp(Integer id) {
        Emp emp = empMapper.selectByPrimaryKey(id);
        return emp;
    }
    /*
     *员工更新
     */
    public void updateEmp(Emp emp) {
        empMapper.updateByPrimaryKeySelective(emp);
    }

    public void deteleEmp(Integer id) {
        empMapper.deleteByPrimaryKey(id);
    }

    public void deteleBatch(List<Integer> ids) {
        EmpExample empExample = new EmpExample();
        EmpExample.Criteria criteria = empExample.createCriteria();
        criteria.andEmpIdIn(ids);
        //delete from xxx where emp_id in(1,2,3)
        empMapper.deleteByExample(empExample);
    }
}
